package com.pub.stripe.controller;


import com.pub.stripe.model.CreateOrderEntity;
import com.pub.stripe.model.CreateRefundEntity;
import com.pub.stripe.service.OrderService;
import com.stripe.Stripe;
import com.stripe.model.*;
import com.stripe.model.checkout.Session;
import com.stripe.param.*;
import com.stripe.param.checkout.SessionCreateParams;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/stripe")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建支付会话
     * 1、创建产品
     * 2、设置价格
     * 3、创建支付信息 得到url
     * @return
     */
    @PostMapping("/order/pay")
    public String pay(@Validated @RequestBody CreateOrderEntity createOrderEntity) {
        return orderService.pay(createOrderEntity);
    }

    /**
     *  发放退款
     * @return
     */
    @PostMapping("/order/refund")
    public void refund(@Validated @RequestBody CreateRefundEntity createRefund) {
        orderService.refund(createRefund);
    }
}
